﻿using JshRCSWebApi.Infrastructure.Domain.DTO.SysService;
using ZstdSharp.Unsafe;

namespace JshRCSWebApi.API.Controllers.SysService
{
    public class DictionaryController : BaseController
    {
        private readonly DictionaryService _dictionaryService;

        public DictionaryController(IHttpContextAccessor httpContextAccessor, DictionaryService dictionaryService) : base(httpContextAccessor)
        {
            this._dictionaryService = dictionaryService; 
        }

        /// <summary>
        /// 新增字典
        /// </summary>
        /// <param name="addDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddDictionary([FromBody] DictionaryAddDTO addDTO)
            => await Task.Run(async () => await _dictionaryService.AddDictionary(addDTO,Convert.ToInt32(GetUser("ID"))));

        /// <summary>
        /// 修改字典
        /// </summary>
        /// <param name="updateDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> UpdateDictionary([FromBody] DictionaryUpdateDTO updateDTO)
            => await Task.Run(async () => await _dictionaryService.UpdateDictionary(updateDTO, Convert.ToInt32(GetUser("ID"))));

        /// <summary>
        /// 删除字典
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteDictionary(long ID)
            => await Task.Run(async () => await _dictionaryService.DeleteDictionary(ID));

        /// <summary>
        /// 获取字典集合
        /// </summary>
        /// <param name="searchDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetDictionaryList([FromBody] DictionarySearchDTO searchDTO )
          => await Task.Run(async () => await _dictionaryService.GetDictionaryList(searchDTO));

        /// <summary>
        /// 根据key获取字典
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetDictionaryByKey(string key)
            => await Task.Run(async () => await _dictionaryService.GetDictionaryByKey(key));
    }
}
